--------------------------------------------------------------------------------
Fractal Landscapes - AKA "3-D Fractals by Michiel Van De Panne"
--------------------------------------------------------------------------------
"fracland.dsk" - A conversion for the CoCo 3 by Andrew L. Ayers (c1987-1991)
--------------------------------------------------------------------------------

Hello, everyone! I first uploaded this conversion to the TRS-80 Color Computer
Facebook group on August 23rd, 2025:

https://www.facebook.com/groups/2359462640/permalink/10163106156102641/

I had mentioned in my writeup to the file that I had converted it from an orig-
inal work I had found in an old issue of Creative Computing magazine, circa 
1984-1986, back when I was a much younger person, but I couldn't recall the ex-
act year or month, or even the author's name!

A round of thanks to Guillaume Major; one of the regular contributors to the FB 
forum, he located a copy of the magazine article. It was found in the July 1985 
issue, and it was originally written by Michiel Van De Panne. He provided a link 
to a textual excerpt of the article - which unfortunately didn't include the 
source code listings:

https://www.atarimagazines.com/creative/v11n7/78_3D_fractals_a_new_graph.php

However, a useful link to a scan of the original magazine was provided:

https://archive.org/details/creativecomputing-1985-07/page/n83/mode/2up?view=theater

...except it isn't very readable, so I put together my own clipping of the art-
icle ("3-D Fractals - Creative Computing - July 1985.pdf"). More on that later.

After he located that article, he also took my writeup, and a copy of the Atari
Magazines excerpt, put it together in a ZIP file, and uploaded it to the Color
Computer Archive. I do thank him for that, but I wanted to make things a bit
better structured, and so that is the reason for this version you are reading 
about.

I do want to stress that I only converted the code to the CoCo 3's Super 
Extended Color Basic, and that I was not the author of it; that honor goes to
Mr. Van De Panne. In 1985 I was 11-12 years old, and there was no way I had the
understanding to write such code, and even when I converted it, which had to
be a few years later (probably sometime in high school, as I was very into both
fractals and 3D graphics during that time - still am, to an extent!), I had only
the vaguest ideas about how it worked.

Also, I could've sworn there was an IBM PCjr version of it in that article, but
apparently, my memory ain't what it once was. So if I had to guess, I probably
used either the Apple II or Macintosh versions as the base for the conversion,
or maybe a combo of the two. Who knows...certainly not me.

So, with that, here is my original writeup to the FB file, "fracland.dsk", which
is included in this archive (note, I have made minor updates to correct grammar,
spelling, and to clarify in areas).

--------------------------------------------------------------------------------
About "fracland.dsk" - TRS-80 Color Computer (CoCo) (Facebook Group)
--------------------------------------------------------------------------------

Andrew Ayers @ August 23rd, 2025:

After I saw the post from Marc Maltais with the SIN3D.BAS, and made a comment 
about it, I was about to comment on this disk image I dug out of my archive.

It is old and fragile, so be kind with it. It will run on a CoCo 3, and is des-
igned for composite mode, as that is what I had back then when I put it togeth-
er, and when I got a CM-8, I don't think I ever updated the colors for it (un-
less it is located in some other forgotten corner of my archive).

To get started, and to see what can be done, load it into your favorite CoCo 3
emulator (or real hardware if you have it), then type RUN"FRACMENU then press 
ENTER.

You'll be presented a simple menu on the 40 column screen, with four options, 
one of which (number 4) will exit you back to the system. Press one of the opt-
ions 1-3 (you don't need to press ENTER), and it will load from the disk image 
one of three pre-generated fractal mountain pictures that I made...well, a long, 
long time ago (btw - "Graphics Magic" is what I named my fantasy graphics gener-
ation company as a kid - lol).

To return back to the menu, hit the break key; the screen will clear, then wait 
a bit, and the menu will re-display. When you're done, press "4". 

NOTE: You must use option "4" to exit cleanly from the menu (BREAK will not work
as it is disabled); the system uses the high-speed poke (though I'm not sure why 
I did that - maybe to make the menu show faster, I guess), and using option "4" 
will revert the system back to normal speed; in the process, though, it clears 
the menu program from memory (so if you want to see the menu's code, just LOAD
it, then LIST it).

Once you've exited the menu, take a look at the directory contents using the DIR
command (you might want to switch to 40 or 80 columns to see everything).

The program which generated those images is named "FRACTALS.BAS". If I remember 
right, I keyed it in from a copy of "Creative Computing" magazine (the issue 
month/year I don't recall, but if I had to guess - somewhere between 1984-1986; 
I also recall it was a special "graphics" issue, and had an article on how to 
take better photographs of your monitor - things weren't as simple as they are
nowadays, for any youngsters reading this).

It was originally written by another individual, whose name I forget, for the 
Apple IIe and the IBM PCjr (I think) - I don't believe it had a CoCo 1/2 conver-
sion, and the CoCo 3 didn't exist when it was published.

If you LIST the program, and take a look through it, you'll see it is quite com-
plex...and if you know anything about 3D graphics, you'll also note that there 
isn't any 3D projection/rotation code (though curiously, there are SIN/COS refs;
there's also a curious construction with a variable called VT in one of those 
sections - I think it's all part of making the triangles).

What the algorithm and code actually do, I believe is called a "midpoint dis-
placement" - where it subdivides a large triangle into smaller and smaller tri-
angles, then displaces each point on the mesh by some random amount, which res-
ults in the final image of mountains, land, and water. That's about the most I 
can say about it, because I haven't really super-analyzed the code, or what the 
2-letter variables may have stood for. Perhaps with the original article in 
hand, and some background from wikipedia on the midpoint displacement algorithm 
and other references about "fractal mountain generation", you can figure out 
more about it.

    *(see my further notes below)
    
You'll also notice in the code where it will prompt you for the number of levels 
to use; this is part of the iterative displacement process: The more levels you 
pick, the smaller the triangles of the mesh will be...and the longer it will 
take to generate the final image. I don't recall what my sample images were gen-
erated with, but probably something like a 7 or an 8 maybe. Let it run and ret-
urn after some coffee - or use an emulator and boost the speed if you're impat-
ient.

Once the image is done, hit BREAK or ENTER (I think) to return back to the sys-
tem. Then, if you want to save the image, run the program "FRCTCHNG.BAS" to alt-
er the image (to make it look like the demo images - you'll also need a blank 
floppy, because the demo one is full, no granuals free). You also may want to 
look at the code first, to see how it works. You need to have the image saved 
first (the code is there for it, but not used in that way), it then will load in 
the image, make the changes for the "legend", then saves it back out in the 
"usual manner" for CoCo 3 HSCREEN 2 images.

Honestly - that program needs an update - but a quick hack might be to put in a 
line 35 to GOTO 160, then when you run it, I think the POKEs at the start (IIRC; 
see line 20) keep the HSCREEN command from clearing the screen, then it will ask 
for a name (8 characters or less, because it uses it for the filename), then 
show the image and alter it, then save it out to the floppy. You can then load 
up one of the other demo "loaders" and alter it to load your new image (and add 
it to the menu, or create a new menu to your liking, etc).

What would be really nice would be to alter that menu to run the generator, then 
for the generator to do the alterations and save the image out - and maybe some 
way for the menu to load the images, instead of having a fixed number of image
loaders. Also, maybe adding break and error trapping to all of the pieces (like 
for instance, breaking out of the generator would take you back to the menu - if 
the generation is taking too long). Plus updates for selecting CMP or RGB. Maybe 
a way to generate the image in HSCREEN 4? Lots of possibilities here!

Have fun with it... :)

--------------------------------------------------------------------------------

So there you have it. What was interesting was reading the code in the article,
which was a bit more enlightening, though I haven't done a deep dive. The code,
it seems, does have some form of a 3D rotation/tilt system, and maybe some form
of projection, but it isn't like anything I've seen before (ie - matrices for
rotation, division of X/Y by Z then multiplication by a factor to correct for 
various things, etc). 

The author describes what the level input is for, and how it works - and you can
see from his description, the number subdivisions per level rise very quickly,
exponentially or more (Level 1=4 triangles, Level 2=16 triangles, Level 3=64
triangles, etc); basically each level quadruples the number of triangles. For
the 4096 triangle mesh he mentions, that would be at Level 6...

I have no idea how long it would take to run that on the CoCo 3, even with the
high-speed poke in place...

I'm sure the ones I generated were not that detailed, as I wasn't that patient
as a kid (still ain't for some things!). But you might want to have that level
of detail if you convert it to run in the 640x192x4 mode.

Another idea for saving the images would be to save the mesh in array D(64,32),
instead of the image itself; I'm not exactly sure how to do it, but the naive
way would be to save each point in the array separately, perhaps as an ASCII CSV
file, of 32 rows of 64 values, or vice-versa. This would allow the data to be
portable, too.

The other way might be to use VARPTR to find the array in memory, then use PEEKs
to pull the data out, or maybe just do a "SAVEM" of the memory to the floppy
device. Not as easy to read or as portable, but might be faster when saving and
loading. 

Both methods, hopefully, would result in much smaller files; the only problem
would be that you would need to re-plot them in order to display, which is in-
herently a slow process.

--------------------------------------------------------------------------------

In addition to the disk image and this file, there is also a PDF copy of the
Creative Computing article. I included it because frankly, the PDF (or DJVU, 
take yer pick) version at Archive.org stinks. 

I am not sure what or why it was made that way, but it was. The only way to fix 
it, is to download the huge CBZ version (which is only huge because every page 
is saved a giant TIFF!), convert the TIFFs to JPEGs (which will get 'em each 
down to about 1MB, from 20MB or whatever; ymmv, settings for conversion will 
affect things, yadayada), then convert those JPEGs into a PDF. 

Doing it that way, you'll get a sane size for the magazine as a whole.

So that's what I did for the article itself (plus the front cover) - then I ran
it thru another utility Bash script of mine that shrinks things even further; it
turned out pretty well (and helped me debug a problem in my script!).

Now I just have to do it for the entire issue...

(and then, at some point down the road, for all of the issues, because I have 
them all somewhere, and they are all terrible looking - ugh!)

--------------------------------------------------------------------------------

Ok - I hope you enjoyed this extended romp thru things; if you decide to make
any of the mods to things like I mentioned, please share 'em!

- Andrew L. Ayers, August 27th, 2025

--------------------------------------------------------------------------------

